package com.linkgie.galaxyframework.templating.model.maven;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Maven 项目；
 * <p>
 * 
 * {@link MavenProject} 的定义表示了一个 Maven 项目模板所需的上下文状态；
 * 
 * @author huanghaiquan
 *
 */
public class MavenProject extends MavenArtifact {

	private MavenArtifact parent;

	private Packaging packaging;

	private String name;

	private String description;

	private Map<String, MavenModule> modules = new LinkedHashMap<>();

	private MavenProperties properties = new MavenProperties();

	private List<MavenDependency> dependencies = new LinkedList<MavenDependency>();

	private DependencyManagement dependencyManagement;

	private MavenBuild build;

	private Map<String, MavenJavaSource> javaSources = new LinkedHashMap<String, MavenJavaSource>();

	private List<MavenJavaResources> resources = new LinkedList<>();

	public MavenArtifact getParent() {
		return parent;
	}

	public void setParent(MavenArtifact parent) {
		this.parent = parent;
	}

	public Packaging getPackaging() {
		return packaging;
	}

	public void setPackaging(Packaging packaging) {
		this.packaging = packaging;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Map<String, MavenModule> getModules() {
		return modules;
	}

	public Set<String> getModuleNames() {
		return modules.keySet();
	}

	public void setModules(Map<String, MavenModule> modules) {
		this.modules = new LinkedHashMap<>(modules);
	}

	public void addModules(List<MavenModule> modules) {
		for (MavenModule module : modules) {
			this.modules.put(module.getName(), module);
		}
	}
	
	public void addModule(MavenModule module) {
		this.modules.put(module.getName(), module);
	}

	public MavenProperties getProperties() {
		return properties;
	}

	public void setProperties(MavenProperties properties) {
		this.properties = properties;
	}

	public List<MavenDependency> getDependencies() {
		return dependencies;
	}

	public void setDependencies(List<MavenDependency> dependencies) {
		this.dependencies = dependencies;
	}
	
	public void addDependencies(MavenDependency... dependencies) {
		if (dependencies == null) {
			return;
		}
		for (MavenDependency dependency : dependencies) {
			this.dependencies.add(dependency);
		}
	}

	public DependencyManagement getDependencyManagement() {
		return dependencyManagement;
	}

	public void setDependencyManagement(DependencyManagement dependencyManagement) {
		this.dependencyManagement = dependencyManagement;
	}

	public MavenBuild getBuild() {
		return build;
	}

	public void setBuild(MavenBuild build) {
		this.build = build;
	}

	public Map<String, MavenJavaSource> getJavaSources() {
		return javaSources;
	}

	public void setJavaSources(Map<String, MavenJavaSource> javaSources) {
		this.javaSources = new LinkedHashMap<>(javaSources);
	}
	
	public void addJavaSources(List<MavenJavaSource> javaSources) {
		for (MavenJavaSource javaSource : javaSources) {
			this.javaSources.put(javaSource.getDirectory(), javaSource);
		}
	}
	
	public void addJavaSources(MavenJavaSource... javaSources) {
		for (MavenJavaSource javaSource : javaSources) {
			this.javaSources.put(javaSource.getDirectory(), javaSource);
		}
	}

	public List<MavenJavaResources> getResources() {
		return resources;
	}

	public void setResources(List<MavenJavaResources> resources) {
		this.resources = resources;
	}

	// -----------------------------------------

	public static class DependencyManagement {

		private List<MavenDependency> dependencies;

		public List<MavenDependency> getDependencies() {
			return dependencies;
		}

		public void setDependencies(List<MavenDependency> dependencies) {
			this.dependencies = dependencies;
		}
	}

}
